<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of user_group
 *
 * @author badboy
 */
class User_Group extends Default_My_Model
{ 
    function __construct()
    {
        parent::__construct();
    }
    
    function get_data($where)
    {
        if($where != "")
        {
            $where = " WHERE $where ";
        }
        
        return $this->db->query("
            SELECT a.id_group_user, a.group_user, a.keterangan, a.default_hak_akses, a.master_group AS id_master_group, b.group_user AS master_group FROM mt_group_user a LEFT JOIN mt_group_user b ON a.master_group = b.id_group_user $where ORDER BY group_user ASC
        ");
    }
    
    function get_data_query($where)
    {
        if($where != "")
        {
            $where = " WHERE $where ";
        }
        
        return "SELECT a.id_group_user, a.group_user, a.keterangan, a.default_hak_akses, a.master_group AS id_master_group, b.group_user AS master_group FROM mt_group_user a LEFT JOIN mt_group_user b ON a.master_group = b.id_group_user $where ORDER BY group_user ASC";
    }
    
    function get_data_by_id($id)
    {
        $user_group = $this->get_object("
            SELECT a.id_group_user, a.group_user, a.keterangan, a.default_hak_akses, a.master_group AS id_master_group, b.group_user AS master_group FROM mt_group_user a LEFT JOIN mt_group_user b ON a.master_group = b.id_group_user WHERE a.id_group_user = $id
        ");
        
        return $user_group;
    }
    
    function get_data_master_grup($id = null)
    {
        if($id == null)
        {
            return $this->db->query("
                SELECT * FROM mt_group_user ORDER BY group_user ASC 
            ");
        }
        else
        {
            return $this->db->query("
                SELECT * FROM mt_group_user WHERE id_group_user != $id ORDER BY group_user ASC 
            ");
        }
    }
    
    function count_all_records()
    {
        /*return $this->get_scalar("
            SELECT COUNT(id_group_user) AS total FROM mt_group_user
        ", "total");*/
        return $this->reltuples_num_rows("mt_group_user");
    }
}

?>
